package canss.webservice.controls;

import org.apache.beehive.controls.api.bean.Control;
import org.apache.beehive.controls.api.bean.ControlImplementation;

import canss.encoder.DBStringEncoder;
import canss.webservice.model.Event;

import weblogic.jdbc.SQLExceptionWrapper;

import java.io.Serializable;
import java.sql.Timestamp;

@ControlImplementation
public class EventControlImpl implements EventControl, Serializable
{
	private static final long serialVersionUID = 7281516179908930975L;

	@Control
	private BusinessSystemDB businesssystemDB;


	public int getNumofEventByMID(String _mid) throws SQLExceptionWrapper
	{
		if (_mid == null)
			throw new SQLExceptionWrapper(new RuntimeException(
					"illegal argument"));
		int ret = businesssystemDB.getNumofEventByMID(DBStringEncoder
				.Server2DB(_mid));
		return ret;
	}
	
	public int getEntireNumofEvent() throws SQLExceptionWrapper
	{
		int ret = businesssystemDB.getEntireNumofEvent();
		return ret;
	}
	
	public Event[] getEntireEvent() throws SQLExceptionWrapper
	{
		Event[] ret = businesssystemDB.getEntireEvent();
		return ret;
	}
	
	public Event[] getEventByMID(String _mid) throws SQLExceptionWrapper
	{
		Event[] ret = businesssystemDB.getEventByMID(_mid);
		return ret;
	}

	public Boolean addNewEvent(String _tblMID_mid, Integer _tblEventDescription_eventid, long _canssevent_timecreatedatt_timestamp, String _canssevent_extradata) throws SQLExceptionWrapper
	{
		int ret = businesssystemDB.addNewEvent(_tblMID_mid, _tblEventDescription_eventid, new Timestamp(_canssevent_timecreatedatt_timestamp), _canssevent_extradata );
		return ret>0;
	}

	public int removeEventUntil(long _canssevent_timecreatedatt_timestamp) throws SQLExceptionWrapper
	{
		int ret = businesssystemDB.removeEventUntil(new Timestamp(_canssevent_timecreatedatt_timestamp));
		return ret;
	}

	
	public String getEventExtradata(String _mid, Integer _eventid, Long _seqnum, Timestamp _timestamp) throws SQLExceptionWrapper
	{
		String[] ret = businesssystemDB.getEventExtradata(_mid, _eventid, _seqnum, _timestamp);
		if(ret!=null && ret.length>0)
			return ret[0];
		else
			return null;
	}
	

}